package codetop;

import java.util.PriorityQueue;
import java.util.Queue;

public class Code215 {
    public int findKthLargest(int[] nums, int k) {
        Queue<Integer>queue=new PriorityQueue<>((x,y)->(x-y));
        for (int i = 0; i < nums.length; i++) {
            if (queue.size()<k)queue.offer(nums[i]);
            int num=nums[i];
            if (num>queue.peek()){
                queue.offer(num);
                queue.poll();
            }
        }
        return queue.poll();
    }
}
